import UIKit
import Flutter

@main
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // 注册默认插件
        GeneratedPluginRegistrant.register(with: self)

        // 获取 FlutterViewController
        guard let controller = window?.rootViewController as? FlutterViewController else {
            return super.application(application, didFinishLaunchingWithOptions: launchOptions)
        }

        // 获取 FlutterPluginRegistrar 并注册 VideoSaver 插件
        if let registrar = controller.registrar(forPlugin: "VideoSaver") {
            VideoSaver.register(with: registrar)
        } else {
            print("Failed to get registrar for VideoSaver plugin")
        }

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}